//
//  SCChooseWuliuController.m
//  shangcheng
//
//  Created by 张艳江 on 2019/6/14.
//  Copyright © 2019 张艳江. All rights reserved.
//

#import "SCChooseWuliuController.h"

@interface SCChooseWuliuController ()<UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) UITableView *tableView;
@property (strong, nonatomic) NSArray     *wuliuArray;

@end

@implementation SCChooseWuliuController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"选择物流";
    self.lineView.hidden = NO;
    
    //设置的tableView
    [self setUpTableView];
    
    //获取快递公司
    [self requestKuaiDiData];
}
- (void)setUpTableView{
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0.5, kScreenW, kScreenH-kTopHeight) style:UITableViewStylePlain];
    self.tableView.backgroundColor = BGColor;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorColor = RGB(239, 239, 239);
    self.tableView.tableFooterView = [UIView new];
    [self.view addSubview:self.tableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.wuliuArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    SCModel *model = self.wuliuArray[indexPath.row];
    cell.textLabel.text = model.name;
    cell.textLabel.font = SCFont(15);
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    SCModel *model = self.wuliuArray[indexPath.row];
    if (self.chooseWuliuName) {
        self.chooseWuliuName(model.name);
    }
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - 获取数据
- (void)requestKuaiDiData{
    
    NSDictionary *dict = @{@"token":Token};
    NSString *url = [MyTool splicingWithUrl:@"admin.php?g=System&c=GiftAppOrder&a=Service_express"];
    [SVProgressHUD showWithStatus:@"加载中..."];
    [[NetworkRequestTool sharedNetworkTool] POST:url parameters:dict finished:^(id result, NSString *error) {
        [SVProgressHUD dismiss];
        self.wuliuArray = [SCModel mj_objectArrayWithKeyValuesArray:result[@"data"]];
        [self.tableView reloadData];
    }];
}



@end
